package com.lw.leetcode.bit.b;

/**
 * 260. 只出现一次的数字 III
 *
 * @Author liw
 * @Date 2021/5/7 16:32
 * @Version 1.0
 */
public class SingleNumber2 {

    public static void main(String[] args) {
//        String str = "-26,-26,-32,-68,-32,-8,-8,-36,-12,-96,-60,-36,-36,-12,-10,-10,-13,-31,-13,-8,-8,8,8,-35,-11,-15,-11,9,-89,-53,-29,-29,-5,-45,-27,-29,15,-35,-11,-15,-11,9";
//        String str = "[-82,-46,-22,-22,2,-38,-20,-22,22,-28,-4,-8,-4,16]";
        String str = "[-178,-258,-70,-258,-150,-46,-66,2,26,-246,-138,-66,-66,6,-86,-126,-32,-126,-72,-46,-66,46,66,-16,8,4,8,28,-246,-138,-66,-66,6,-114,-60,-66,66,-84,-12,-24,-12,48]";
//        String str = "[110,-130,270,-130,-210,2,-58,270,162,-166,-246,-58,-246,-138,26,-34,66,-34,-54,-70,-10,-46,14,246,138,66,66,-6,-190,-270,-82,-270,-162,-58,-78,-10,14,-258,-150,-78,-78,-6,58,-62,138,-62,-102,4,-26,138,84,-80,-120,-26,-120,-66,26,-34,66,-34,-54,-26,34,-66,34,54,-52,-22,-28,2,-32,-2,-28,2,-8,22,246,138,66,66,-6,114,60,66,-66,84,12,24,12,-48,-184,-264,-76,-264,-156,-52,-72,-4,20,-252,-144,-72,-72,0,-92,-132,-38,-132,-78,-52,-72,40,60,-22,2,-2,2,22,-252,-144,-72,-72,0,-120,-66,-72,60,-90,-18,-30,-18,42]";
//        String str = "[6,-106,6,-106,-106,-24,-52,-60,-24,-64,-64,-52,-88,-52,0,-28,0,-28,-28,-44,-16,-20,8,-104,-68,-44,-44,-20,-36,-36,-24,-60,-24,0,0,-16,8,-76,-40,-16,-16,8,6,-50,6,-50,-50,-9,-23,-27,-9,-29,-29,-23,-41,-23,0,-28,0,-28,-28,0,28,0,28,28,-39,-25,-15,-1,-19,-5,-15,-1,5,19,-93,-57,-33,-33,-9,-49,-31,-33,11,-39,-15,-19,-15,5,-43,-43,-31,-67,-31,-7,-7,-23,1,-83,-47,-23,-23,1,-15,-15,-9,-27,-9,-7,-7,21,21,-25,-1,-5,-1,19,-79,-43,-19,-19,5,-35,-17,-19,25,-25,-1,-5,-1,19]";
        String[] split = str.split(",");
        System.out.println(split.length);
    }

    public int[] singleNumber(int[] nums) {
        int item = 0;
        for (int num : nums) {
            item = item ^ num;
        }
        int n = 1;
        while ((item & 1) == 0) {
            item = item >> 1;
            n = n << 1;
        }
        int a = 0;
        int b = 0;
        for (int num : nums) {
            if ((num & n) == 0) {
                a = a ^ num;
            } else {
                b = b ^ num;
            }
        }
        return new int[]{a, b};
    }
}
